<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>找回密码</title>
		<link rel="stylesheet" href="css/login.css" />
		<link rel="stylesheet" href="css/ali/font_508934_kve4so1x2xs10pb9.css" />
		<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
		<script src="js/jquery.min.js"></script>
		<script src="js/login.js"></script>
		<script src="js/register.js"></script>
		
		<script>
			$server = 'http://localhost:8080/';
			window.onload = function(){
				$username = GetQueryString('username');
				$.ajax({
					url: $server + 'user/forget_get_question.do',
					type: 'POST',
					datatype: 'json',
					data: {username: $username},
					corssDomain: true,
					xhrFields:{
						withCredentials: true // 携带跨域cookie
					},
					success: function(result){
						console.log(result);
						if (result.code == 200){
							$('#question').val(result.data);
						}else{
							alert(result.msg);
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown){
						alert(textStatus);
					}
				});
			}
			
			function forgetPassword(){
				$answer = $('#answer').val();
				if ($answer == "" || $answer == null)
				{
					alert("答案不能为空");
					return;
				}
				$question = $('#question').val();
				$username = GetQueryString('username');
				$.ajax({
					url: $server + 'user/forget_check_answer.do',
					type: 'POST',
					datatype: 'json',
					data: {username: $username, question: $question, answer: $answer},
					corssDomain: true,
					xhrFields:{
						withCredentials: true // 携带跨域cookie
					},
					success: function(result){
						console.log(result);
						if (result.code == 200){
							$token = result.data.token;
							window.location.href = encodeURI('forgetReset.html?username='+$username+'&token='+$token);
						}else{
							alert(result.msg);
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown){
						alert(textStatus);
					}
				});
			}
			
			// 从地址栏获取参数
			function GetQueryString(name)
			{
			     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			     var r = decodeURI(window.location.search.substr(1)).match(reg);
			     if(r!=null)return  unescape(r[2]); return null;
			}
		</script>
	</head>
	<body>
		<div class="top">
			<div class="top_logo">
				<img src="img/login_logo.jpg" />
			</div>
			<div class="top_line"></div>
		</div>
		<div class="main0">
			<div class="main">
				<div class="input-group" style="width: 300px; margin: 0 auto;">
					<span class="input-group-addon">问题</span>
					<input id="question" type="text" class="form-control" disabled/>
				</div>
				<div class="input-group" style="width: 300px; margin: 10px auto 0 auto;">
					<span class="input-group-addon">答案</span>
					<input id="answer" type="text" class="form-control"/>
				</div>
				<div style="width: 60px; margin: 10px auto 0 auto;">
					<button type="button" class="btn btn-primary" onclick="forgetPassword()">提交</button>
				</div>
			</div>
		</div>
		<div class="footer">Copyright &copy 2019 Bowen University . 桂ICP备888888888号</div>
	</body>
</html>
